import numpy as np
from typing import Union


def accuracy_score(y_true: Union[list, np.array], y_pred: Union[list, np.array]) -> float:
    """
    计算准确率的函数
    """

    y_true = np.array(y_true).reshape(-1)
    y_pred = np.array(y_pred).reshape(-1)
    # 确保输入的数组具有相同的长度
    assert len(y_true) == len(y_pred), "标签长度不一致"

    # 计算预测准确的数量
    correct = np.sum(y_true == y_pred)

    # 计算预测准确率
    accuracy = correct / len(y_true)

    return accuracy


def reverse_dict(dictionary: dict) -> dict:
    """
    将一个字典的键值反转

    Args:
        dictionary (dict): 要反转的字典

    Returns:
        dict: 键值反转后的字典
    """
    reversed_dict = {value: key for key, value in dictionary.items()}
    return reversed_dict
